const webpack = require("webpack");
const path = require("path");
const BundleAnalyzerPlugin =
  require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const config = {
  mode: "production",
  entry: { index: "./src/index.tsx", previewer: "./src/previewer.tsx" },
  devtool: "source-map",
  output: {
    path: path.join(__dirname, "./lib"),
    filename: (pathData) => {
      return pathData.chunk.name + ".js";
    },
    library: "square9",
    libraryTarget: "umd",
  },
  module: {
    rules: [
      {
        test: /\.(js|jsx|ts|tsx)$/,
        loader: "ts-loader",
        exclude: /node_modules/,
      },
      {
        test: /\.png$/,
        use: [
          {
            loader: "url-loader",
            options: {
              mimetype: "image/png",
            },
          },
        ],
      },
      {
        test: /\.css$/,
        use: [MiniCssExtractPlugin.loader, "css-loader"],
      },
    ],
  },
  resolve: {
    extensions: [".js", ".jsx", ".tsx", ".ts"],
  },
  externals:
    /^(react)|(mobx)|(@ke)|(rmc)|(ant-design)|(antd)|(brower-image-combiner)|(@juggle)|(jszip)/,
  plugins: [
    new BundleAnalyzerPlugin({
      analyzerMode: "static",
      openAnalyzer: false,
    }),
    new MiniCssExtractPlugin(),
    new webpack.DefinePlugin({
      version: JSON.stringify(require("./package.json").version),
    }),
  ],
};

module.exports = config;
